<?php

require_once('define.php'); 


class xdata
{
	
	//任务类型转换
	public function ex_tasktype($n){
		$data = json_decode(TASKTYPE,false);
		return $data->$n;
	}
	
	//采集类型转换
	public function ex_collection($n){
		$data = json_decode(COLLECTION,false);
		return $data->$n;
	}
	
	//商户类型
	public function business_category($n){
		$data = array();
		$data[1] = 'A类户';
		$data[2] = 'B类户';
		$data[3] = 'C类户';
		$data[0] = '';
		
		return $data[$n];
	}
	
	//商户经营状态
	public function business_operating($n){
		$data = array();
		$data[1] = '正常经营';
		$data[2] = '初始申请';
		$data[3] = '暂停营业';
		$data[4] = '注销';
		$data[5] = '责令停业';
		$data[0] = '';
		
		$data[2702] = '正常经营';
		$data[2701] = '初始申请';
		$data[2703] = '暂停营业';
		$data[2705] = '注销';
		$data[2706] = '责令停业';
		$data[''] = '';
		
		return $data[$n];
	}
	
	public function apcd_task_pool_status($n){
		$data = array();
		$data[1] = '待分配';
		$data[2] = '已分配';
		$data[3] = '已完成';
		$data[4] = '过期终止';
		$data[5] = '过期结转';
		$data[0] = '';
		
		return $data[$n];
	}
	
	
	/*
	* 获取星期名 
	* 星期下标
	* 返回字符串
	*/
	public function week_name($i){
		$week = array(
			1 => '周一',
			2 => '周二',
			3 => '周三',
			4 => '周四',
			5 => '周五',
			6 => '周六',
			0 => '周日'
		);
		
		return $week[$i];
	}
	
		
	/*
	* 获取来源
	* 来源的下标
	* 返回字符串
	*/
	public function sources_name($i){
		$sources = array(
			0 => '营销',
			1 => '专卖',
			2 => '内管',
			3 => '考核组',

		);
		return $sources[$i];
	}
	
	//是否处理
	public function handlestate_name($i){
		$handlestate = array(
			0 => '未处理',
			1 => '已处理',
		);
		return $handlestate[$i];
	}	
	//异常情况
	public function abnormal_name($i){
		$abnormal = array(
			1 => '未开门',
			2 => '违规销售',
			3 => '张贴二维码未到位',
			4 => '未亮证经营',
			5 => '未入户签到',
			6 => '未张贴联系电话到位',
			7 => '证照 证人 证址不相符',
			8 => '未购卷烟',
			9 => '客户经理拜访情况',
		);
		return $abnormal[$i];
	}	
	
	
	/*
	* 获取页面显示页码数
	* total	数据总条数	cur_page 当前页数	row	每页显示条数	url 查询地址
	* 返回分页html页面	
	*/
	public function show_page($total,$row,$cur_page,$url){
		$page_num = ceil($total/$row);
		$show_page = array();
		
		//分页显示
		if($total != 0){
			if($cur_page-2 <= 1){
				$startshow = 1;
				$endshow = 5;
			}else if($cur_page-2 >= 2 ){
				$startshow = $cur_page-2;
				if($cur_page+2 <= $page_num)
					$endshow = $cur_page+2;
				else
					$endshow = $page_num;
			} 
			
			if($cur_page+2 >= $page_num ){
				$startshow = $page_num-4;
				if($startshow<=0){
					$startshow = 1;
				}
			}
			if($page_num<5){
				$endshow = $page_num;
			}
		}else{				//如果数据为空
			$startshow = 0;
			$endshow = 0;
		}

		$page = '';
		if($total != 0){
			$page .= '<div class="fenye" style="height:40px;">';
			$page .= '  <ul class="pager">';
		   if($cur_page != 1){
				$page .= '		<li class="previous" link="'.$url.'"><a href="#">上一页</a></li>';
				$page .= '		<li class="page_query" attr_page="1" link="'.$url.'"><a href="#">首页</a></li>';
		   }
			  
			for($i=$startshow;$i<=$endshow;$i++){
				$page .= '		<li class="page_query ';
				if($i == $cur_page){
				$page .= 'active';
				}
				$page .='" attr_page="'.$i.'" link="'.$url.'">';
				$page .= '			<a href="#">'.$i.'</a>';
				$page .= '		</li>';
			}
			
			if($cur_page != $page_num){
				$page .= '		<li class="page_query" attr_page="'.$page_num.'" link="'.$url.'"><a href="#">尾页</a></li>';
				$page .= '		<li class="next" link="'.$url.'"><a href="#">下一页</a></li>';
			}
			$page .= '  </ul>';
			$page .= '	</div>';
		}
		
		return $page;
	}
	
}